﻿using B.S.DataBase.MyProject.Domain.Materials;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.MaterialsCommand.QueryMaterialsCommand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.MaterialsCommandCommand.QueryMaterialsCommandHandler
{ /// <summary>
  /// 计量单位动态下拉查询处理方法
  /// </summary>
    public class UnitOfMeasurementQueryCommandHandler:IRequestHandler<UnitOfMeasurementQueryCommand,APIResult<List<UnitOfMeasurementModel>>>
    {
        /// <summary>
        /// 计量单位的仓储接口
        /// </summary>
        private readonly IBaseRepository<UnitOfMeasurementModel> uRepo;
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="uRepo"></param>
        public UnitOfMeasurementQueryCommandHandler(IBaseRepository<UnitOfMeasurementModel>uRepo)
        {
            this.uRepo = uRepo;
        }
        /// <summary>
        /// 处理方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>W
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<List<UnitOfMeasurementModel>>> Handle(UnitOfMeasurementQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<UnitOfMeasurementModel>> result = new APIResult<List<UnitOfMeasurementModel>>();
            var list = uRepo.GetAll().Result;
            result.data = list.ToList();
            result.Msg = APIEnum.查询成功.ToString();
            result.Code = APIEnum.成功;
            result.Count = list.Count();
            return Task.FromResult(result);
        }
    }




}
